<template>
	<view class="showGoods">
		<view class="title">
			特产展示
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in techanList" :key="index">
				<view class="img">
					<image :src="item.img" mode="aspectFill"></image>
				</view>
				<view class="content">
					<view class="name">{{ item.name }}</view>
					<view class="description">{{ item.text }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'

const techanList = ref([])

async function getTechanData() {
	try {
		const response = await uni.request({
			url: 'https://smzoycm4.lc-cn-n1-shared.com/1.1/classes/Techan',
			method: 'GET',
			header: {
				'X-LC-Id': 'SmZOYcM4LNO7YdHkQPsVNj3s-gzGzoHsz',
				'X-LC-Key': 'h0fwbXM9QnmZb0ppHlzLVs1X',
			}
		});
		
		if (response.statusCode === 200) {
			techanList.value = response.data.results;
		} else {
			uni.showToast({
				icon: "error",
				title: '获取数据失败'
			});
		}
	} catch (error) {
		uni.showToast({
			icon: "error",
			title: '网络请求错误'
		});
	}
}

onLoad(() => {
	getTechanData()
})
</script>

<style scoped>
.showGoods {
	padding: 20rpx;
}

.title {
	font-size: 32rpx;
	color: #ff6700;
	margin-bottom: 20rpx;
	padding-left: 20rpx;
}

.list {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
}

.item {
	width: 48%;
	background: #fff;
	border-radius: 12rpx;
	margin-bottom: 20rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	overflow: hidden;
}

.img {
	width: 100%;
	height: 200rpx;
	overflow: hidden;
}

.img image {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.content {
	padding: 16rpx;
}

.name {
	font-size: 28rpx;
	color: #333;
	font-weight: bold;
	margin-bottom: 8rpx;
}

.description {
	font-size: 24rpx;
	color: #666;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 3;  /* 限制显示3行 */
	-webkit-box-orient: vertical;
	line-height: 1.4;
}
</style>
